<template>
  <div class="adress">
    <!-- 头部 -->
    <van-sticky>
      <van-nav-bar v-if="isHome" title="黑马优购" />
      <van-nav-bar v-else title="黑马优购">
        <div class="left_arrow" @click="()=>{ $router.go(-1) }" slot="left">
          <van-icon name="arrow-left" />
          <span>返回</span>
        </div>
      </van-nav-bar>
    </van-sticky>
    <div>
      <van-address-list
        v-model="chosenAddressId"
        :list="savelist"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="checked"
      />
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";

export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [],
      savelist: window.sessionStorage.getItem("savelist")
        ? JSON.parse(window.sessionStorage.getItem("savelist"))
        : []

    };
  },
  created() {
    this.addressEdit();
  },
  computed: {
    isHome: function() {
      if (this.$route.path == "/" || this.$route.path == "/home") {
        return true;
      } else {
        return false;
      }
    }
  },
  methods: {
    addressEdit() {
      // (this.list = JSON.parse(localStorage.getItem("savelist")) || []);
      console.log(this.list);
    },
    onAdd() {
      this.$router.push("/address_edit");
    },
    onEdit(item, index) {
      console.log(item, index);

      this.$router.push({ path: "/address_edit", query: { item } });
    },
    checked(item, index) {
      
      // console.log(item.address, index);
    }
  }
};
</script>

<style lang="less" scoped>
.adress {
  position: relative;
}

.footer {
  position: fixed;
  display: block;
  bottom: 0;
  width: 100%;
  height: 50px;
  line-height: 50px;
  text-align: center;
  color: #fff;
  background-color: #d81e06;
}
</style>